package cn.demo.um.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import cn.demo.common.annotation.Log;
import cn.demo.common.core.controller.BaseController;
import cn.demo.common.core.domain.R;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import cn.demo.common.enums.BusinessType;
import cn.demo.um.domain.UmUserFocus;
import cn.demo.um.service.IUmUserFocusService;
import cn.demo.common.utils.poi.ExcelUtil;
import cn.demo.common.core.page.PageR;
import cn.demo.common.core.page.PageQuery;
import com.mybatisflex.core.paginate.Page;


/**
 * 用户关注列Controller
 *
 * @author xtjun
 * @date 2024-06-05
 */
@Tag(name = "用户关注列")
@RestController
@RequestMapping("/um/umUserFocus")
public class UmUserFocusController extends BaseController {
    @Resource
    private IUmUserFocusService umUserFocusService;

    @Operation(summary = "查询用户关注列列表")
    @PreAuthorize("@ss.hasPermi('um:umUserFocus:list')")
    @GetMapping("/list")
    public PageR<UmUserFocus> list(UmUserFocus umUserFocus, PageQuery pageQuery) {
        Page<UmUserFocus> page = umUserFocusService.selectUmUserFocusPage(umUserFocus, pageQuery);
        return PageR.ok(page);
    }

    @Operation(summary = "导出用户关注列列表")
    @PreAuthorize("@ss.hasPermi('um:umUserFocus:export')")
    @Log(title = "用户关注列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UmUserFocus umUserFocus) {
        List<UmUserFocus> list = umUserFocusService.selectUmUserFocusList(umUserFocus);
        ExcelUtil<UmUserFocus> util = new ExcelUtil<UmUserFocus>(UmUserFocus.class);
        util.exportExcel(response, list, "用户关注列数据");
    }

    @Operation(summary = "获取用户关注列详细信息")
    @PreAuthorize("@ss.hasPermi('um:umUserFocus:query')")
    @GetMapping(value = "/{userId}")
    public R<UmUserFocus> getInfo(@PathVariable("userId") String userId) {
        return R.ok(umUserFocusService.selectUmUserFocusByUserId(userId));
    }

    @Operation(summary = "新增用户关注列")
    @PreAuthorize("@ss.hasPermi('um:umUserFocus:add')")
    @Log(title = "用户关注列", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody UmUserFocus umUserFocus) {
        return toAjax(umUserFocusService.insertUmUserFocus(umUserFocus));
    }

    @Operation(summary = "修改用户关注列")
    @PreAuthorize("@ss.hasPermi('um:umUserFocus:edit')")
    @Log(title = "用户关注列", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody UmUserFocus umUserFocus) {
        return toAjax(umUserFocusService.updateUmUserFocus(umUserFocus));
    }

    @Operation(summary = "删除用户关注列")
    @PreAuthorize("@ss.hasPermi('um:umUserFocus:remove')")
    @Log(title = "用户关注列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public R remove(@PathVariable List<String> userIds) {
        return toAjax(umUserFocusService.deleteUmUserFocusByUserIds(userIds));
    }
}
